package com.ctsi.question.service;


import com.ctsi.commons.util.UtilValidate;
import com.ctsi.commons.util.id.UUIDGenerator;
import com.ctsi.commons.util.response.Page;
import com.ctsi.framework.mybatis.support.MybatisGenericDao;
import com.ctsi.question.dto.NextPlanDTO;
import com.ctsi.question.entity.NextPlanEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * NextPlanEntity Service 类
 * @author   zhangjw
 * @description  NextPlanEntity
 * @created	 Wed Aug 28 15:47:57 CST 2019
 */

@Service
public class NextPlanEntityService {
	private static final Logger logger=LoggerFactory.getLogger(NextPlanEntityService.class);
	@Autowired
	private MybatisGenericDao dao;

	/**
	 * 查询下一步工作计划
	 * @param reportId
	 * @param userId
	 * @return
	 */
	public List<NextPlanDTO> findNextPlanDetails(String reportId, String userId){
		Map<String,Object> params = new HashMap<>();
		params.put("reportId",reportId);
		params.put("userId",userId);
		return (List<NextPlanDTO>) dao.queryForList(NextPlanEntity.class.getName()+".findNextDetails",params);
	}


	/**
	 * 查询工作计划详情
	 */
	public NextPlanDTO findPlanDetails(String planId, String userId){
		Map<String,Object> params = new HashMap<>();
		params.put("detailId",planId);
		params.put("userId",userId);
		return (NextPlanDTO) dao.queryForObject(NextPlanEntity.class.getName()+".findNextDetails",params);
	}

	/**
	 * 添加
	 */
	public void insertNextPlanEntity(NextPlanEntity nextPlanEntity){
		if(UtilValidate.isEmpty(nextPlanEntity.getId()))
			nextPlanEntity.setId(UUIDGenerator.getId());
		logger.debug("insert {}",nextPlanEntity);
		dao.insert(nextPlanEntity);
	}
	/**
	 * 动态更新
	 */
	public int updateNextPlanEntityByPKSelective(NextPlanEntity nextPlanEntity){
		logger.debug("updateByPrimaryKeySelective {}",nextPlanEntity);
		return dao.update(NextPlanEntity.class.getName()+".updateByPrimaryKeySelective", nextPlanEntity);
	}
	/**
	 * 更新
	 */
	public int updateNextPlanEntity(NextPlanEntity nextPlanEntity){
		logger.debug("update {}",nextPlanEntity);
		return dao.update(nextPlanEntity);
	}


	public NextPlanEntity editNextPlanEntityById(String id){
		if(UtilValidate.isEmpty(id))
			return null;
		logger.debug("editById {}",id);
		return (NextPlanEntity)dao.queryForObject(NextPlanEntity.class.getName()+".edit", id);
	}
	/**
	 * 根据ID查找 NextPlanEntity对象
	 */
	public NextPlanEntity findNextPlanEntityById(String id){
		if(UtilValidate.isEmpty(id))
			return null;
		logger.debug("findById {}",id);
		return dao.get(NextPlanEntity.class, id);
	}
	/**
	 * 删除NextPlanEntity对象
	 */
	public int removeNextPlanEntity(String id){
		if(UtilValidate.isNotEmpty(id))
			return dao.delete(NextPlanEntity.class.getName()+".delete", id);
			//return dao.remove(id);
		return 0;
	}

	/**
	 * 详细页查询
	 */
	public NextPlanEntity findByDetail(String id){
		return (NextPlanEntity)dao.queryForObject(NextPlanEntity.class.getName()+".findByDetail",id);
	}
	/**
	 * 多条件查询结果
	 */
	public Page<NextPlanEntity> findByMulitCondition(Map<String,Object> param , int start , int pageSize){
		logger.debug("findByMulitCondition {}",param);
		if(pageSize<0||pageSize>2000)
			pageSize=Page.DEFAULT_PAGE_SIZE;
		if(start!=-1)
			return dao.queryPage(NextPlanEntity.class.getName()+".selectMulitCondition", param, start, pageSize);
		else{
			throw new RuntimeException("参数不正确 !!");
		}
	}
	/**
	 * 多条件查询结果不分页
	 */
	public List<NextPlanEntity> find(Map<String,Object> map){
		logger.debug("find {}",map);
		return (List<NextPlanEntity>)dao.queryForList(NextPlanEntity.class.getName()+".selectByMap",map);
	}

}
